package com.oms.servlet;

import com.liudecai.utils.servlet.BaseServlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/MenuServlet")
public class MenuServlet extends BaseServlet {
	public static final long serialVersionUID = 1L;

    /**
     * Default constructor. 
     */
    public MenuServlet() {
    }
    
    public String ToView(HttpServletRequest request, HttpServletResponse response) throws IOException {
    	String toview=request.getParameter("toview");
    	System.out.println(toview);
    	
		if ("add_class".equals(toview)) {
			return "r:/admin/add_class.jsp";
		}else if("show_class".equals(toview)){
			return "r:/admin/show_class.jsp";
		}else if("add_food".equals(toview)){
			return "r:/admin/add_food.jsp";
		}else if ("show_food".equals(toview)) {
			return "r:/admin/show_food.jsp";
		}else if ("add_notice".equals(toview)) {
			return "r:/admin/add_notice.jsp";
		}else if ("show_notice".equals(toview)) {
			return "r:/admin/show_notice.jsp";
		}else if ("show_order".equals(toview)) {
			return "r:/admin/show_order.jsp";
		}else if ("show_today_order".equals(toview)) {
			return "r:/admin/show_today_order.jsp";
		}else if ("show_search_order".equals(toview)) {
			return "r:/admin/show_search_order.jsp";
		}else if ("show_admin".equals(toview)) {
			return "r:/admin/show_admin.jsp";
		}else if ("show_user".equals(toview)) {
			return "r:/admin/show_user.jsp";
		}/*else if ("loginout".equals(toview)) {
			return "r:/admin/loginout.jsp";
		}*/else if ("loginout".equals(toview)) {
			loginout(request, response);
		}/*else if ("index".equals(toview)) {
			return "r:/admin/index.jsp";
		}*/else {
			return "无效的菜单";
		}
		return toview;
    }
    
    public String loginout(HttpServletRequest request, HttpServletResponse response) throws IOException {
//		response.sendRedirect(request.getContextPath()+"/MenuServlet?method=ToView&toview=index");
    	//response.setHeader("Refresh","3",URL=http://www.it315.org"); 
		// return "r:/admin/loginout.jsp";
    		//分别注释下面两条语句中的一条，查看各自的运行效果
    	System.out.println(request.getContextPath()+"/MenuServlet?method=ToView&toview=index");
    	request.getSession().invalidate();
        //response.setHeader("Refresh","2");
        //response.setHeader("Refresh","2;URL=http://www.it315.org");
    	response.setHeader("Refresh","2;URL="+request.getContextPath()+"/admin/");
        //response.getWriter().println(new java.util.Date());
    	response.getWriter().println("退出成功!2秒后跳转!");
		return null; 
	}

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
